package com.wyh.domain.dto.gfive;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.wyh.domain.po.gfive.Role;
import com.wyh.domain.po.gfive.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.util.*;

@Data
@NoArgsConstructor
@Component
@JsonIgnoreProperties(ignoreUnknown = true)
public class LoginUser implements UserDetails {



    private List<Role> roles;


    private Set<String> permissions;

    private User user;

    /**
     * 用户唯一标识
     */
    @ApiModelProperty("用户唯一标识")
    private String token;

    /**
     * 登录时间
     */
    @ApiModelProperty("登录时间")
    private Long loginTime;

    /**
     * 过期时间
     */
    @ApiModelProperty("过期时间")
    private Long expireTime;


    public LoginUser (List<Role> roles, Set<String> permissions,User user){
        this.user=user;
        this.permissions=permissions;
        this.roles=roles;
    }



    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


}
